// Map 对象保存键值对。任何值(对象或者原始值) 都可以作为⼀个键或⼀个值。
const launches = new Map();
let latestFlightNumber = 100;
// 数据⽰例
const launch = {
    flightNumber: 100,
    mission: 'Kepler Exploration X',
    rocket: 'Explorer IS1',
    launchDate: new Date('December 27, 2030'),
    target: 'Kepler-442 b',
    customer: ['GKD', 'NASA'],
    upcoming: true,
    success: true,
};
// 设置键值对
launches.set(launch.flightNumber, launch);
// 判断是否存在指定 ID 的发射任务
function existsLaunchWithId(launchId) {
    return launches.has(launchId);
}
function getAllLaunches() {
    return Array.from(launches.values());
}
function addNewLaunch(launch) {
    latestFlightNumber++;
    launches.set(
        latestFlightNumber,
        Object.assign(launch, {
            success: true,
            upcoming: true,
            customers: ['GKD', 'NASA'],
            flightNumber: latestFlightNumber,
        })
    );
}
// 取消指定 ID 的发射任务
function abortLaunchById(launchId) {
    const aborted = launches.get(launchId);
    aborted.upcoming = false;
    aborted.success = false;
    return aborted;
}
module.exports = {
    existsLaunchWithId,
    getAllLaunches,
    addNewLaunch,
    abortLaunchById,
};